package com.tadpole.music.holder.me;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.me.ZhenTiSearchBean;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.utils.NoDoubleClickListener;

/**
 * Created By 孙岩
 * on 2020/12/26
 */
public class ZhenTiWorkViewHolder extends BaseViewHolder {
    private View itemView;
    private ZhenTiSearchBean.DataBean bean;
    private BaseAdapter.OnItemClickListener onItemClickListener;
    //错题数
    private TextView tvCuoTi;
    //时间
    private TextView tvShiChang;
    //正确率
    private TextView tvZhengQueLv;
    //作答时间
    private TextView tvTime;
    //状态
    private ImageView ivState;
    //分数
    private TextView tvCount;

    public ZhenTiWorkViewHolder(View itemView, ZhenTiSearchBean.DataBean bean, BaseAdapter.OnItemClickListener onItemClickListener) {
        super(itemView);
        this.itemView = itemView;
        this.bean = bean;
        this.onItemClickListener = onItemClickListener;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void init(final int position) {
        tvCuoTi = itemView.findViewById(R.id.tvCuoTi);
        tvShiChang = itemView.findViewById(R.id.tvShiChang);
        tvZhengQueLv = itemView.findViewById(R.id.tvZhengQueLv);
        tvTime = itemView.findViewById(R.id.tvTime);
        ivState = itemView.findViewById(R.id.ivState);
        tvCount = itemView.findViewById(R.id.tvCount);

        tvCuoTi.setText(bean.getMonth_exam_static().get(position).getErr_num()+"道");
        tvShiChang.setText(bean.getMonth_exam_static().get(position).getTime()+"分钟");
        tvZhengQueLv.setText(bean.getMonth_exam_static().get(position).getScore()+"%");
        tvTime.setText(bean.getMonth_exam_static().get(position).getCreated_at());
        tvCount.setText(bean.getMonth_exam_static().get(position).getScore()+"");

        if(bean.getMonth_exam_static().get(position).getScore()>=85){
            ivState.setImageResource(R.mipmap.youxiu);
        }else if(bean.getMonth_exam_static().get(position).getScore()<85&&bean.getMonth_exam_static().get(position).getScore()>=60){
            ivState.setImageResource(R.mipmap.lianghao);
        }else{
            ivState.setImageResource(R.mipmap.jiaocha);
        }

        itemView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onItemClickListener.onItemClick(itemView,position);
            }
        });
    }
}
